// DatoNotatListeForm.cpp : implementation file
//

#include "stdafx.h"
#include "EBASApp.h"
#include "DatoNotatListeForm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDatoNotatListeForm

IMPLEMENT_DYNCREATE(CDatoNotatListeForm, CFormView)

CDatoNotatListeForm::CDatoNotatListeForm()
	: CFormView(CDatoNotatListeForm::IDD)
{
	//{{AFX_DATA_INIT(CDatoNotatListeForm)
	m_cpr = _T("");
	//}}AFX_DATA_INIT

	CEBASAppApp::g_nCurrentView = DATONOTATLISTE;
}

CDatoNotatListeForm::~CDatoNotatListeForm()
{

}

void CDatoNotatListeForm::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDatoNotatListeForm)
	DDX_Text(pDX, IDC_EDIT_DATONOTATLISTE_CPR, m_cpr);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDatoNotatListeForm, CFormView)
	//{{AFX_MSG_MAP(CDatoNotatListeForm)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDatoNotatListeForm diagnostics

#ifdef _DEBUG
void CDatoNotatListeForm::AssertValid() const
{
	CFormView::AssertValid();
}

void CDatoNotatListeForm::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDatoNotatListeForm message handlers

void CDatoNotatListeForm::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();

	EBASDLLLib::IStuderendePtr pStuderende;
	pStuderende = CEBASAppApp::gpEbasSession->AktivStuderende;
	
	if (NULL != pStuderende) {
		m_cpr = (char*)pStuderende->CPRNr;

		EBASDLLLib::IEnumDatoNotatPtr pEnumDatonotat;
		pEnumDatonotat = pStuderende->DatoNotater;
	
		IUnknown * pUnk = NULL; ULONG curr = 0, fetched = 0;

		pEnumDatonotat->Next(&pUnk, &fetched); curr = fetched;
		while (0 < curr) {
			EBASDLLLib::IDatoNotatPtr pDatonotat;
			pUnk->QueryInterface(&pDatonotat);
			pUnk = NULL;

			bstr_t line = pDatonotat->Dato + " * " + pDatonotat->Emne;
			m_oversigt.AddString(line);

			curr--;
			pEnumDatonotat->Next(&pUnk, &fetched); 
		}
	}

	UpdateData(FALSE);
}

